﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LK.Math
{
    public partial class Bits
    {
        static public ulong GetULong(ulong[] arr, int index, int len, int bitmov) {
            if (bitmov <=  0) {
                if (bitmov <= -64) return 0;
                return len == 0 ? 0 : arr[index] << - bitmov;
            }
            int i = bitmov / 64;
            bitmov &= 63;
            if (i >=  len-1) {
                if (i >= len) return 0;
                return arr[index + i] >> bitmov;
            }
            if (bitmov == 0) return arr[index + i];
            return (arr[index + i] >> bitmov) | (i+1==len?0: (arr[index + i+1] << (64-bitmov)));
        }
    }
}
